// 玩家菜单插件


string author = "Live";
string pluginName = "Player_Menu 玩家菜单";
string version = "1.0";

// 插件初始化
void OnPluginInit()
{
	// 设置插件信息
	PluginData::SetAuthor(author);
	PluginData::SetName(pluginName);
	PluginData::SetVersion(version);

	// 提示
	ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);

	//ConCommand::Create( "as_player", ShowPlayerMenu, "Show the player menu", LEVEL_MODERATOR );

	Events::Player::PlayerSay.Hook( @PlayerSay );
	Events::Player::OnMenuExecuted.Hook( @OnMenuExecuted );


	// Register base commands
	//AdminMenu::RegisterBaseCommands();
}

// 插件被卸载
void OnPluginUnload()
{
	//ConCommand::Remove( "as_admin" );
}

// 当玩家say
HookReturnCode PlayerSay(CTerrorPlayer@ pPlayer, CASCommand@ pArgs)
{
	string arg1 = pArgs.Arg( 1 );
	if ( Utils.StrEql( arg1, "!m" ) )
	{ 
		OpenMenu( pPlayer );
	}
	int gamemode = ThePresident.GetGameModeType();
	
	if( Utils.StrEql( arg1, "!b" ) )
	{
		if (gamemode == CT_EXTRACTION ){
			openBuyMenu( pPlayer );
			Chat.PrintToChat(pPlayer,"因为官方的BUG，购买{hotpink}必须要留两个格子\n（Because the official API provided has bugs, you {hotpink}must have two free backpack spaces）");
		}else{
			Chat.PrintToChat(pPlayer,"{hotpink}目前只允许救援模式买枪");
		}
		
	}
	return HOOK_CONTINUE;
}


void OpenMenu( CTerrorPlayer@ pPlayer )
{
	if ( pPlayer is null ) return;
	Menu pMenu;
	pMenu.SetID( "myas_MenuBase" );
	pMenu.SetTitle( "Player Menu" );
	pMenu.AddItem( "自杀 idioctonia" );
	pMenu.Display( pPlayer, -1 );
}

void openBuyMenu( CTerrorPlayer@ pPlayer ){
	if (pPlayer is null ) return;
    Menu pMenu;
	pMenu.SetID( "shop" );
	pMenu.SetTitle( "商店" );
	pMenu.AddItem( "连喷" );
	pMenu.AddItem( "m4" );  
	pMenu.AddItem( "沙鹰" );
    pMenu.AddItem( "手雷" );
	pMenu.Display( pPlayer, -1 );
}

HookReturnCode OnMenuExecuted(CTerrorPlayer@ pPlayer, const string &in szID, int &in iValue)
{
	if( szID == "myas_MenuBase"){
		int TeamNumber = 0;
		switch( iValue ){
			case 1:
				TeamNumber = pPlayer.GetTeamNumber();
				if(TeamNumber == 2){
					Engine.RunConsoleCommand( "admin slay !" + pPlayer.entindex() );
					Chat.PrintToChat( pPlayer, "{gold}[{green}Server{gold}]{white} " + pPlayer.GetPlayerName()+ "自杀了！" );
				}else{
					Chat.PrintToChat(pPlayer,"{gold}[{green}Server{gold}]{white}:只有做人的时候才能自杀！（Suicide is only possible when in the survivor camp）");
				}
				break;
		}
	}else if( szID == "shop" ){
		switch( iValue ){
			case 1:
				pPlayer.GiveWeapon("Autoshotgun");
				break;
			case 2:
				pPlayer.GiveWeapon("ar15");
				break;
			case 3:
				pPlayer.GiveWeapon("handcannon");
				break;
            case 4:
                pPlayer.GiveWeapon("grenade");
                break;
		}
	}
	return HOOK_CONTINUE;
}




